package com.neuedu.hisweb.controller.neureg;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.hisweb.entity.JsonResult;
import com.neuedu.hisweb.entity.MedicalCard;
import com.neuedu.hisweb.entity.vo.MedicalCardVo;
import com.neuedu.hisweb.service.impl.MedicalCardServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RestController
@RequestMapping("/medicalCard")
public class MedicalCardController {
    @Autowired
    private MedicalCardServiceImpl iMedicalCardService;

    @GetMapping("/page")
    public JsonResult<Page>  getMedicalCardByPage(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
                                                  @RequestParam(value = "count", defaultValue = "10") Integer count,
                                                  @RequestParam(value = "keyword",required = false)String keyword){
        Page<MedicalCardVo> page=Page.of(pn,count);
        iMedicalCardService.selectPage(page,keyword);
        return new JsonResult<Page>(page);
    }

    @PostMapping("/add")
    public JsonResult<MedicalCard> addMedicalCard(@RequestBody MedicalCard medicalCard){
        boolean rs= iMedicalCardService.save(medicalCard);
        if(rs)
            return new JsonResult<MedicalCard>(medicalCard);
        else
            return new JsonResult<>("添加失败");
    }
    @PostMapping("/update")
    public JsonResult<MedicalCard> updateMedicalCard(@RequestBody MedicalCard medicalCard) {
        boolean rs = iMedicalCardService.updateById(medicalCard);
        if (rs)
            return new JsonResult<MedicalCard>(medicalCard);
        else
            return new JsonResult<MedicalCard>("修改失败");
    }

    @PostMapping("/del")
    public JsonResult<MedicalCard> delMedicalCard(@RequestParam(value = "id", required = true) Integer id) {
        boolean rs = iMedicalCardService.removeById(id);
        if (rs) {
            JsonResult<MedicalCard> jsonResult = new JsonResult<>();
            jsonResult.setResult(true);
            return jsonResult;
        } else return new JsonResult<MedicalCard>("删除失败");
    }

}
